package udp;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

//继承上述服务器的代码结构
public class DicUdpServe extends UdpServer{
    //实例化一个哈希表
    private Map<String,String> dictionary=new HashMap<>();
    //用打表的方式创建字典
    public DicUdpServe(int port) throws SocketException {
        super(port);
        dictionary.put("cat","小猫");
        dictionary.put("dog","小狗");
        dictionary.put("日本人","畜生");

    }

    //重写process方法
    @Override
    public String process(String request) {
        return dictionary.getOrDefault(request, "这个词俺也不会!");
    }

    public static void main(String[] args) throws IOException {
        System.out.println("字典服务器正在运行中");
        DicUdpServe dicServer=new DicUdpServe(8000);
        dicServer.start();
    }
}
